﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shop.Core.Domain.Catalog;
using Shop.Core.Domain.Common;

namespace Shop.Core.Domain.Orders
{
    public partial class Order
    {
        protected virtual OrderProduct AddProductCore(Product product, int quantity, OrderProductType productType)
        {
            OrderProduct op = new OrderProduct();
            op.CreatedBy = this.Customer.Id;
            op.CreatedOn = DateTime.UtcNow;
            op.Discount = new Money(0);
            op.OriginalProduct = product;
            op.ProductType = productType;
            op.Quantity = quantity;
            this.Products.Add(op);
            return op;
        }

        protected virtual void RecalculatePaymentStatus()
        {
            if (this.ActualCapturedAmount >= this.GrandTotal)
            {
                this.PaymentStatus = Payments.PaymentStatues.PaymentComfired;
            }
            else if (this.ActualCapturedAmount.Value > 0)
            {
                this.PaymentStatus = Payments.PaymentStatues.PartiallyPaid;
            }
            else
            {
                this.PaymentStatus = Payments.PaymentStatues.PaymentPending;
            }
        }
    }
}
